package cn.aitrox.ry.service.oss.config;

import cn.ucloud.ufile.api.object.ObjectConfig;
import cn.ucloud.ufile.auth.ObjectAuthorization;
import cn.ucloud.ufile.auth.UfileObjectLocalAuthorization;
import cn.ucloud.ufile.util.UfileProtocol;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class UcloudConfiguration {


    @Value("${ucloud.ucloudPublicKey:}")
    private String ucloudPublicKey;
    @Value("${ucloud.ucloudPrivateKey:}")
    private String ucloudPrivateKey;

    @Bean("ucloudObjectConfigLan")
    public ObjectConfig genObjectConfigLan() {
        ObjectConfig objectConfig = new ObjectConfig("internal-cn-sh2-01", "ufileos.com");
        return objectConfig.withProtocol(UfileProtocol.PROTOCOL_HTTP);
    }

    @Bean("ucloudObjectConfigWan")
    public ObjectConfig genObjectConfigWan() {
        ObjectConfig objectConfig = new ObjectConfig("cn-sh2", "ufileos.com");
        return objectConfig.withProtocol(UfileProtocol.PROTOCOL_HTTP);
    }

    @Bean("ucloudObjectAuthorization")
    public ObjectAuthorization genObjectAuthorization() {
        return new UfileObjectLocalAuthorization(ucloudPublicKey, ucloudPrivateKey);
    }
}
